fsck: Add --all to print all corrupted object
authorAlexander Larsson <alexl@redhat.com>
Thu, 17 May 2018 08:06:24 +0000 (10:06 +0200)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 24 May 2018 21:00:52 +0000 (21:00 +0000)
Stopping on the first error is nice if you just want to know if everything is ok, but
if you want to figure out all that is wrong its nice to be able to continue and
print all corruptions.

Closes: #1591
Approved by: cgwalters

src/ostree/ot-builtin-fsck.c
tests/test-corruption.sh

index b3f06e4d6db0b07964ce6618796da0d80ee36ef3..83000c6e1b6ab6cc4c4578c6bc97d06be93c275f 100644 (file)
@@ -31,6 +31,7 @@
 
 static gboolean opt_quiet;
 static gboolean opt_delete;
+static gboolean opt_all;
 static gboolean opt_add_tombstones;
 static gboolean opt_verify_bindings;
 static gboolean opt_verify_back_refs;
@@ -43,6 +44,7 @@ static gboolean opt_verify_back_refs;
 static GOptionEntry options[] = {
   { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, "Add tombstones for missing commits", NULL },
   { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL },
+  { "all", 'a', 0, G_OPTION_ARG_NONE, &opt_all, "Don't stop on first error", NULL },
   { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL },
   { "verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_verify_bindings, "Verify ref bindings", NULL },
   { "verify-back-refs", 0, 0, G_OPTION_ARG_NONE, &opt_verify_back_refs, "Verify back-references (implies --verify-bindings)", NULL },
@@ -94,6 +96,11 @@ fsck_one_object (OstreeRepo            *repo,
               (void) ostree_repo_delete_object (repo, objtype, checksum, cancellable, NULL);
               object_missing = TRUE;
             }
+          else if (opt_all)
+            {
+              *out_found_corruption = TRUE;
+              g_printerr ("%s\n", temp_error->message);
+            }
           else
             {
               g_propagate_error (error, g_steal_pointer (&temp_error));
index 4994e277e1e3bed6ee3c0656919c3f79635ef830..2b5e61bb7c3c23043eb293e1b61c50300c5438bf 100755 (executable)
@@ -21,7 +21,7 @@
 
 set -euo pipefail
 
-echo "1..8"
+echo "1..9"
 
 . $(dirname $0)/libtest.sh
 
@@ -118,6 +118,7 @@ rev=$($OSTREE rev-parse test2)
 
 filechecksum=$(ostree_file_path_to_checksum repo test2 /firstfile)
 echo corrupted >> repo/$(ostree_checksum_to_relative_object_path repo $filechecksum)
+unset filechecksum
 
 assert_not_has_file repo/state/${rev}.commitpartial
 
@@ -129,3 +130,25 @@ assert_file_has_content_literal err.txt "Marking commit as partial: $rev"
 assert_has_file repo/state/${rev}.commitpartial
 
 echo "ok corrupt file"
+
+cd ${test_tmpdir}
+rm repo files -rf
+setup_test_repository "bare"
+
+rev=$($OSTREE rev-parse test2)
+firstfilechecksum=$(ostree_file_path_to_checksum repo test2 /firstfile)
+echo corrupted >> repo/$(ostree_checksum_to_relative_object_path repo $firstfilechecksum)
+secondfilechecksum=$(ostree_file_path_to_checksum repo test2 /baz/cow)
+echo corrupted >> repo/$(ostree_checksum_to_relative_object_path repo $secondfilechecksum)
+
+assert_not_has_file repo/state/${rev}.commitpartial
+
+if $OSTREE fsck -a --delete 2>err.txt; then
+    assert_not_reached "fsck unexpectedly succeeded"
+fi
+assert_file_has_content err.txt "Corrupted file object.*${firstfilechecksum}"
+assert_file_has_content err.txt "Corrupted file object.*${secondfilechecksum}"
+assert_file_has_content_literal err.txt "Marking commit as partial: $rev"
+assert_has_file repo/state/${rev}.commitpartial
+
+echo "ok fsck --all"